/*
As3 Performances Analyzer
Copyright (C) 2011 Ankama Studio

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Contact : seyraud@ankama.com
Project : http://code.google.com/p/as3-performances-analyzer
*/

package types
{
	import ui.components.Graph;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.net.SharedObject;
	
	public class GraphSerie extends EventDispatcher
	{
		//://////////////////////////////////////////////////////
		//:// Variables privées
		//://////////////////////////////////////////////////////
		
		private var _visible : Boolean = true;
		private var _provider : SubProvider;
		private var _dataField : String;
		private var _color : uint;
		private var _renderer : Class = Graph;
		private var _so : SharedObject;
		
		//://////////////////////////////////////////////////////
		//:// Getter / Setter
		//://////////////////////////////////////////////////////
		
		/** Couleur à utiliser */
		public function get color():uint{return _color;}
		public function set color(value:uint):void
		{
			_color = value;
			_so.data.color = value;
			_so.flush();
			dispatchEvent(new Event(Event.CHANGE));
		}

		/** Objet contenant les données */
		public function get provider():SubProvider{return _provider;}
		public function set provider(value:SubProvider):void
		{
			_provider = value;
			dispatchEvent(new Event(Event.CHANGE));
		}

		/** Champ contenant les données */
		public function get dataField():String{return _dataField;}
		public function set dataField(value:String):void
		{
			_dataField = value;
			dispatchEvent(new Event(Event.CHANGE));
		}

		/** Doit-on afficher cette série */
		public function get visible() : Boolean {return true;}
		public function set visible(v : Boolean) : void
		{
			_visible = v;
			_so.data.visible = v;
			_so.flush();
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		/** Class à utiliser pour le rendu */
		public function get renderer() : Class {return _renderer;}
		public function set renderer(c : Class) : void
		{
			_renderer = c;
		}
		
		//://////////////////////////////////////////////////////
		//:// Constructeur
		//://////////////////////////////////////////////////////
		
		public function GraphSerie(p : SubProvider, dataField : String)
		{
			_provider = p;
			_renderer = p.renderer
			_dataField = dataField;
			
			_so = SharedObject.getLocal(p.id + "_" + dataField);
			if(_so.data.color !== null)
				_color = _so.data.color;
			
			if(_so.data.visible !== null)
				_visible = _so.data.visible;
		}
	}
}